package com.ttg.web.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ttg.model.mapper.CostManageAcctDepositAnalysisMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttg.model.po.AcctAnalysisPO;
import com.ttg.model.pojo.CostManageAcctDepositAnalysis;
import com.ttg.model.pojo.CostManageIndustryDepositLoan;
import com.ttg.web.dao.CostManageAcctDepositAnalysisDao;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * (TblCostManageAcctDepositAnalysis) daoImpl
 *
 * @author chenyou
 * @datetime 2025-09-23 15:40:25
 */
@Service
public class CostManageAcctDepositAnalysisDaoImpl extends ServiceImpl<CostManageAcctDepositAnalysisMapper, CostManageAcctDepositAnalysis> implements CostManageAcctDepositAnalysisDao {

    @Override
    public CostManageAcctDepositAnalysis getByUnique(String intervalType, Integer dimType, Integer acctType, String year, String month) {
        LambdaQueryWrapper<CostManageAcctDepositAnalysis> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CostManageAcctDepositAnalysis::getCmadIntervalType,intervalType)
                .eq(CostManageAcctDepositAnalysis::getCmadAcctDimType,dimType)
                .eq(CostManageAcctDepositAnalysis::getCmadAcctType,acctType)
                .eq(CostManageAcctDepositAnalysis::getCmadYear,year)
                .eq(CostManageAcctDepositAnalysis::getCmadMonth,month);
        return getOne(wrapper);
    }

    @Override
    public void saveOrUpd(CostManageAcctDepositAnalysis depositAnalysis) {
        CostManageAcctDepositAnalysis old = getByUnique(depositAnalysis.getCmadIntervalType(),depositAnalysis.getCmadAcctDimType(),depositAnalysis.getCmadAcctType(),depositAnalysis.getCmadYear(),depositAnalysis.getCmadMonth());
        if(Objects.isNull(old)){
            save(depositAnalysis);
        }else{
            depositAnalysis.setCmadId(old.getCmadId());
            updateById(depositAnalysis);
        }
    }

    @Override
    public BigDecimal sumPayInterest(AcctAnalysisPO po) {
        return baseMapper.sumPayInterest(po);
    }

    @Override
    public List<CostManageAcctDepositAnalysis> getByParam(AcctAnalysisPO po) {
        return baseMapper.getByParam(po);
    }
}

